package com.tinyseed.emcp.api.productionRule.bean;

import com.tinyseed.emcp.api.basicdata.domain.convert.DTOConvert;
import com.tinyseed.emcp.api.productionRule.entity.Distribution;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @Description
 * @Author Henry
 * @Date 2019-12-18
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DistributionOutputDTO implements Serializable, Comparable<DistributionOutputDTO> {

    /**
     * 唯一主键
     */
    private Long id;

    /**
     * 企业id
     */
    private Long enterpriseId;

    /**
     * 车间id
     */
    private Long workshopId;

    /**
     * 监测点id
     */
    private Long monitorId;

    /**
     * 减排方案id
     */
    private Long producesetId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 最后修改时间
     */
    private Date modifyTime;

    /**
     * 创建人
     */
    private String creator;

    private String enterpriseName;

    private String workshopName;

    private String monitorName;

    /*优先级*/
    private Long level;

    /*0限产，1停产*/
    private Long produceType;

    /*停产百分比*/
    private Double lessProduce;

    /**
     * 最后操作人
     */
    private String modifier;
    public Distribution convertToDistribution() {
        DistributionOutputDTOConvert convert = new DistributionOutputDTOConvert();
        Distribution result = convert.convert(this);
        return result;
    }
    @Override
    public int compareTo(DistributionOutputDTO o) {

        if (this.level < o.level) {
            return -1;
        }
        if (this.level > o.level) {
            return 0;
        }
        if (this.produceType > o.getProduceType()) {
            return 0;
        }
        if (this.produceType < o.getProduceType()) {
            return 0;
        }
        if (this.lessProduce > o.getLessProduce()) {
            return 0;
        }
        return -1;
    }

    private static class DistributionOutputDTOConvert implements DTOConvert<DistributionOutputDTO, Distribution> {

        @Override
        public Distribution convert(DistributionOutputDTO distributionOutputDTO) {
            Distribution distribution = new Distribution();
            BeanUtils.copyProperties(distributionOutputDTO, distribution);
            return distribution;
        }
    }
}
